package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.support.annotation.IdRes;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.mvp.presenter.CarOffShelfPresenter;
import com.bjesc_b2c.app.appraiset.mvp.presenter.impl.CarOffShelfPresenterImpl;
import com.bjesc_b2c.app.appraiset.mvp.view.CarOffshelfView;
import com.bjesc_b2c.app.appraiset.widget.layout.FlowRadioGroup;

import butterknife.Bind;
import butterknife.OnClick;
import master_bean.CarOffShelfBean;

/**
 * Created by yidong on 2017/5/9.
 * 下架界面
 */

public class CarOffShelfActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener, CarOffshelfView {

    @Bind(R.id.rg_scratched)
    FlowRadioGroup flowRadioGroup;
    @Bind(R.id.line_three)
    LinearLayout bjLayout;
    @Bind(R.id.ed_sell_price)
    EditText editSellPrice;
    @Bind(R.id.ed_service_price)
    EditText editServicePrice;
    @Bind(R.id.ed_remarks)
    EditText editRemarks;
    @Bind(R.id.tv_title)
    TextView title;

    private String car_id = "";
    private int status;
    private int termination_type = 0;
    private String strike_price = "";
    private String server_price = "";
    private String termination_text = "默认下架";
    private CarOffShelfPresenter shelfPresenter;

    @Override
    protected int getLayout() {
        return R.layout.activity_off_shelf;
    }

    @Override
    protected void initEventAndData() {
        initView();
    }

    @Override
    protected void createPresenter() {

    }

    protected void initView() {
        flowRadioGroup.setOnCheckedChangeListener(this);
        shelfPresenter = new CarOffShelfPresenterImpl(this);
        car_id = getIntent().getExtras().getString("Car_id");
        status = getIntent().getIntExtra("status",1);
        title.setText("下架");
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
        bjLayout.setVisibility(View.GONE);
        switch (checkedId) {
            case R.id.radio_one:
                termination_type = 1;
                break;
            case R.id.radio_two:
                termination_type = 2;
                break;
            case R.id.radio_three://博精成交
                termination_type = 3;
                bjLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.radio_four:
                termination_type = 4;
                break;
            case R.id.radio_fives:
                termination_type = 5;
                break;
            case R.id.radio_six:
                termination_type = 6;
                break;
        }
    }

    @OnClick({R.id.btn_commit, R.id.iv_return})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_commit:
                if (termination_type == 0) {
                    showToast("请选择终止类型");
                    return;
                } else if (termination_type == 3) {
                    strike_price = editSellPrice.getText().toString();
                    server_price = editServicePrice.getText().toString();
                    if (TextUtils.isEmpty(strike_price)) {
                        showToast("请填写售价");
                        return;
                    } else if (TextUtils.isEmpty(server_price)) {
                        showToast("请填写服务费");
                        return;
                    } else if (!TextUtils.isEmpty(editRemarks.getText().toString())) {
                        termination_text = editRemarks.getText().toString();
                    }
                }
                CarOffShelfBean mbean = new CarOffShelfBean();
                mbean.setCar_id(car_id);
                mbean.setServer_price(server_price);
                mbean.setStrike_price(strike_price);
                mbean.setTermination_car_text(termination_text);
                mbean.setTermination_car_type(termination_type + "");
                mbean.setType(status+"");
                shelfPresenter.pustCarOff(CarOffShelfActivity.this, mbean);
                break;
            case R.id.iv_return:
                finish();
                break;
        }
    }

    @Override
    public void OffshelfBack(String carId) {
        showToast("下架成功！");
        setResult(RequestAndResultCode.CAROFFSHELFACTIVITY_BACK_RESULT);
        finish();

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
